package com.asset.inventory.kt

import android.content.Context
import android.content.Intent
import android.view.inputmethod.InputMethodManager
import androidx.appcompat.app.AppCompatActivity

/**
 *    @author : sibb
 *    date   : 21-4-2
 *    desc   : 活动相关函数
 */
inline fun <reified T> startActivity(context: Context,block: Intent.() -> Unit){
    val intent = Intent(context, T::class.java)
    intent.block()
    context.startActivity(intent)
}

inline fun <reified T> startActivity(context: Context){
    val intent = Intent(context, T::class.java)
    context.startActivity(intent)
}

fun AppCompatActivity.hideSoftKeyboard(){
    val view = currentFocus
    if(view != null){
        val inputManager = getSystemService(AppCompatActivity.INPUT_METHOD_SERVICE) as InputMethodManager
        inputManager.hideSoftInputFromWindow(view.windowToken, InputMethodManager.HIDE_NOT_ALWAYS)
    }
}